home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / APW.SC / SC10PlaySound / Play.asm < prev    next >
Encoding:
Assembly Source File  |  1990-06-24  |  30.3 KB  |  828 lines  |  [TEXT/pdos]

  1. *******************************************************************************
  2. *
  3. * PlaySound -- Version 3.0
  4. *
  5. * (C)  Copyright Apple Computer, Inc. 1988-1990
  6. * All rights reserved.
  7. *
  8. * Developer Technical Support Apple II Sample Code
  9. *
  10. * by Jim MENSCH
  11. *
  12. * This program demonstrates how to use the Apple IIgs freeform sound playback
  13. * capabilities. It allows the user to select a file containing a digitized 
  14. * waveform and play it back at any user selected frequency. 
  15. *******************************************************************************
  16.                     eject
  17.                     
  18. **********************************************************************
  19. *                                                                    *
  20. *             Apple IIGS Source Code Sampler, Volume I               *
  21. *                                                                    *
  22. *           Copyright (c) Apple Computer, Inc. 1988-1990             *
  23. *                       All Rights Reserved                          *
  24. *                                                                    *
  25. *            Written by Apple II Developer Tech Support              *
  26. *                                                                    *
  27. *                                                                    *
  28. *                                                                    *
  29. *  ----------------------------------------------------------------  *
  30. *                                                                    *
  31. *     This program and its derivatives are licensed only for         *
  32. *     use on Apple computers.                                        *
  33. *                                                                    *
  34. *     Works based on this program must contain and                   *
  35. *     conspicuously display this notice.                             *
  36. *                                                                    *
  37. *     This software is provided for your evaluation and to           *
  38. *     assist you in developing software for the Apple IIGS           *
  39. *     computer.                                                      *
  40. *                                                                    *
  41. *     DISCLAIMER OF WARRANTY                                         *
  42. *                                                                    *
  43. *     THE SOFTWARE IS PROVIDED "AS IS" WITHOUT                       *
  44. *     WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,               *
  45. *     WITH RESPECT TO ITS MERCHANTABILITY OR ITS FITNESS             *
  46. *     FOR ANY PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO             *
  47. *     THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH            *
  48. *     YOU.  SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU (AND            *
  49. *     NOT APPLE OR AN APPLE AUTHORIZED REPRESENTATIVE)               *
  50. *     ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,             *
  51. *     REPAIR OR CORRECTION.                                          *
  52. *                                                                    *
  53. *     Apple does not warrant that the functions                      *
  54. *     contained in the Software will meet your requirements          *
  55. *     or that the operation of the Software will be                  *
  56. *     uninterrupted or error free or that defects in the             *
  57. *     Software will be corrected.                                    *
  58. *                                                                    *
  59. *     SOME STATES DO NOT ALLOW THE EXCLUSION                         *
  60. *     OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY              *
  61. *     NOT APPLY TO YOU.  THIS WARRANTY GIVES YOU SPECIFIC            *
  62. *     LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER RIGHTS                *
  63. *     WHICH VARY FROM STATE TO STATE.                                *
  64. *                                                                    *
  65. *                                                                    *
  66. **********************************************************************
  67.                     eject
  68.                     
  69.                     case   on
  70.  
  71.                     copy 2/ainclude/E16.Quickdraw
  72.                     copy 2/ainclude/E16.Memory
  73.                     copy 2/ainclude/E16.Event
  74.                     copy 2/ainclude/E16.Window
  75.                     copy 2/ainclude/E16.Dialog
  76.                     mcopy macros/play.macros
  77.  
  78. DPHandle            gequ 0              ; handle to Tool Direct Page area
  79. DPPointer           gequ DPHandle+4     ; Pointer to Tool Direct Page area
  80. DeRef               gequ DPPointer+4    ; Temprary Handle dereference area
  81. Temp1               gequ DeRef+4        ; temp DPage storage for general use
  82. ScreenMode          gequ mode640        ; used to set scan line SCB
  83. ScreenWidth         gequ 640            ; used to set mouse clamps                
  84.  
  85.  
  86. ;
  87. ;   Dialog Item Numbers
  88. ;
  89.  
  90. ItemPlayB           gequ 1
  91. ItemQuitB           gequ 2
  92. ItemLoadB           gequ 3
  93. ItemRad22           gequ 4
  94. ItemRad16           gequ 5
  95. ItemRad11           gequ 6
  96. ItemRad08           gequ 7
  97. ItemRadUsr          gequ 8
  98. ItemEditUsr         gequ 12
  99. ItemEditVol         gequ 13
  100.  
  101.  
  102.                     EJECT
  103. *******************************************************************************
  104. *
  105. playSounds          start
  106. *
  107. * Description:      This is the main routine of the program, it calls all
  108. *                   other major routines in the proper order.
  109. *
  110. *
  111. * Inputs:           None
  112. *
  113. * Outputs:          None
  114. *
  115. * External Refs:    
  116. *                   Import InitTools
  117. *                   Import EventLoop
  118. *                   Import CloseTools
  119. *                   Import QuitParms
  120. *
  121. * Entry Points:
  122. *
  123. *******************************************************************************
  124.  
  125.                     jsr InitTools
  126.  
  127.                     _ShowCursor
  128.  
  129.                     jsr EventLoop
  130.                     jsr CloseTools
  131.  
  132.                     _Quit QuitParms
  133.  
  134.                     end
  135.  
  136.                     EJECT
  137. *******************************************************************************
  138. *
  139. Globals             data
  140. *
  141. * Description:      Global data for use in all routines of this program
  142. *                   This area also contains data used by the init file.
  143. *
  144. *
  145. * Inputs:           None
  146. *
  147. * Outputs:          None
  148. *
  149. * External Refs:    None
  150. *
  151. * Entry Points:
  152. *                   Export QuitParms
  153. *
  154. *******************************************************************************
  155. *
  156. * Standard Global Data here
  157. *
  158. *******************************************************************************
  159.  
  160. TitleString         str 'Apple IIgs Freeform Sound Demo'
  161. AutString           str 'By Mensch Apple DTS -- Version: 3.0'
  162. VersString          str 'Copyright (c) 1988-1990 Apple Computer'
  163.  
  164. MenuHeight          ds 2                ; Stored height of menu bar
  165. MyID                ds 2                ; application ID
  166. MyDP                ds 2                ; My direct page storage
  167.  
  168. QuitFlag            ds 2
  169. QuitParms           dc i4'0'            ; Pathname of next app
  170.                     dc i2'$00'          ; flags
  171.  
  172.                     EJECT
  173. *******************************************************************************
  174. *
  175. * Application specific data
  176. *
  177. *******************************************************************************
  178. theDialog           ds 4                ; pointer to my dialog
  179.  
  180. MyDialog            ANOP
  181.                     dc i2'29,60,189,460'                    ; bounds rect...
  182.                     dc i2'$FFFF'        ; true visible
  183.                     dc i4'0'            ; refcon=0
  184.                     dc i4'PlayB'        ; Item 1
  185.                     dc i4'QuitB'        ; Item 2
  186.                     dc i4'LoadB'        ; Item 3
  187.                     dc i4'K22B'
  188.                     dc i4'K16B'
  189.                     dc i4'K11B'
  190.                     dc i4'K08B'
  191.                     dc i4'KUsrB'
  192.                     dc i4'KUsrE'
  193.                     dc i4'KVolE'
  194.                     dc i4'KVolS'
  195.                     dc i4'STit'
  196.                     dc i4'NPStat'
  197.                     dc i4'0'            ; end of list!
  198.  
  199. PlayBTitle          dc i1'4',c'Play'
  200. PlayB               ANOP
  201.                     dc i2'1'
  202.                     dc i2'142,316,0,0'
  203.                     dc i2'buttonItem'   ; standard button
  204.                     dc i4'PlayBTitle'
  205.                     dc i2'0'
  206.                     dc i2'0'            ; item flag
  207.                     dc i4'0'            ; no color table
  208.  
  209. QuitBTitle          dc i1'4',c'Quit'
  210. QuitB               ANOP
  211.                     dc i2'2'
  212.                     dc i2'123,316,0,0'
  213.                     dc i2'buttonItem'   ; standard button
  214.                     dc i4'QuitBTitle'
  215.                     dc i2'0'
  216.                     dc i2'0'            ; item flag
  217.                     dc i4'0'            ; no color table
  218.  
  219. LoadBTitle          dc i1'7',c'Open...'
  220. LoadB               ANOP
  221.                     dc i2'3'
  222.                     dc i2'105,308,0,0'
  223.                     dc i2'buttonItem'   ; standard button
  224.                     dc i4'LoadBTitle'
  225.                     dc i2'0'
  226.                     dc i2'0'            ; item flag
  227.                     dc i4'0'            ; no color table
  228.  
  229. K22BTitle           dc i1'6',c'22 Khz'
  230. K22B                ANOP
  231.                     dc i2'4'
  232.                     dc i2'30,10,40,190'
  233.                     dc i2'radioItem'    ; radio button
  234.                     dc i4'K22BTitle'
  235.                     dc i2'0'
  236.                     dc i2'1'            ; item flag: Family 1
  237.                     dc i4'0'            ; no color table
  238.  
  239. K16BTitle           dc i1'6',c'16 Khz'
  240. K16B                ANOP
  241.                     dc i2'5'
  242.                     dc i2'45,10,55,190'
  243.                     dc i2'radioItem'    ; radio button
  244.                     dc i4'K16BTitle'
  245.                     dc i2'0'
  246.                     dc i2'1'            ; item flag
  247.                     dc i4'0'            ; no color table
  248.  
  249. K11BTitle           dc i1'6',c'11 Khz'
  250. K11B                ANOP
  251.                     dc i2'6'
  252.                     dc i2'60,10,70,190'
  253.                     dc i2'radioItem'    ; radio button
  254.                     dc i4'K11BTitle'
  255.                     dc i2'0'
  256.                     dc i2'1'            ; item flag:Family 1
  257.                     dc i4'0'            ; no color table
  258.  
  259. K08BTitle           dc i1'6',c' 8 Khz'
  260. K08B                ANOP
  261.                     dc i2'7'
  262.                     dc i2'75,10,85,190'
  263.                     dc i2'radioItem'    ; radio button
  264.                     dc i4'K08BTitle'
  265.                     dc i2'0'
  266.                     dc i2'1'            ; item flag: family 1
  267.                     dc i4'0'            ; no color table
  268.  
  269. KUsrBTitle          dc i1'17',c'User Supplied:  $'
  270. KUsrB               ANOP
  271.                     dc i2'8'
  272.                     dc i2'90,10,100,154'
  273.                     dc i2'radioItem'    ; radio button
  274.                     dc i4'KUsrBTitle'
  275.                     dc i2'0'
  276.                     dc i2'1'            ; item flag: family 1
  277.                     dc i4'0'            ; no color table
  278.  
  279.  
  280. KUsrEDef            dc i1'6',c'00FF'
  281. KUsrE               ANOP
  282.                     dc i2'12'
  283.                     dc i2'88,154,102,196'
  284.                     dc i2'editLine'
  285.                     dc i4'KUsrEDef'
  286.                     dc i2'4'            ; maximum length of edit item
  287.                     dc i2'0'            ; item flag
  288.                     dc i4'0'            ; no color table
  289.  
  290. KVolEDef            dc i1'6',c'00FF'
  291. KVolE               ANOP
  292.                     dc i2'13'
  293.                     dc i2'28,252,42,294'
  294.                     dc i2'editLine+itemDisable'
  295.                     dc i4'KVolEDef'
  296.                     dc i2'4'
  297.                     dc i2'0'            ; item flag
  298.                     dc i4'0'            ; no color table
  299.  
  300. STitTitle           dc i1'50',c'Digitized sound player By Jim Mensch Apple II DTS'
  301. STit                ANOP
  302.                     dc i2'9'
  303.                     dc i2'1,10,11,380'
  304.                     dc i2'statText+itemDisable'
  305.                     dc i4'STitTitle'
  306.                     dc i2'0'
  307.                     dc i2'0'
  308.                     dc i4'0'
  309.  
  310.  
  311. NPTitle             dc i1'16',c'Now Playing:  ^0    '
  312. NPNoFile            dc i1'15',c'No files loaded'
  313. NPStat              ANOP
  314.                     dc i2'10'
  315.                     dc i2'12,10,22,300'
  316.                     dc i2'statText+itemDisable'
  317.                     dc i4'NPTitle'
  318.                     dc i2'0'
  319.                     dc i2'0'
  320.                     dc i4'0'
  321.  
  322. KVolSTit            dc i1'10',c'Volume:  $'
  323. KVolS               ANOP
  324.                     dc i2'11'
  325.                     dc i2'30,180,40,252'
  326.                     dc i2'statText+itemDisable'
  327.                     dc i4'KVolSTit'
  328.                     dc i2'0'
  329.                     dc i2'0'
  330.                     dc i4'0'
  331.  
  332.  
  333. Rect                ds 8
  334. MyRect              ds 8
  335.  
  336. PromptStr           dc i1'5',c'Hello'   ; SFGetFile record
  337. MyReply             ANOP
  338. MyRGood             ds 2
  339. MyRFType            ds 2
  340. MyRAType            ds 2
  341. MyRName             ds 16
  342. MyRFName            ds 129
  343.  
  344.  
  345. OPParms             ANOP
  346. OPRefNum            dc i2'0'            ; ProDOS 16 open call parm block
  347.                     dc i4'MyRFName'
  348.                     dc i4'0'
  349. GEParms             ANOP
  350. GERefNum            dc i2'0'            ; ProDOS 16 GetEOF Parm block
  351. GESize              dc i4'0'
  352.  
  353. RDParms             ANOP                ; ProDOS 16 read parm block
  354. RDRefNum            dc i2'0'
  355. RDDataBuf           dc i4'0'
  356. RDReqCnt            dc i4'0'
  357.                     dc i4'0'
  358. CLParms             ANOP
  359. CLRefNum            dc i2'0'            ; ProDOS 16 close parm block
  360.  
  361. ; Record used for FFStartsound to describe the freeform wave
  362.  
  363. MyFFRecord          dc i4'0'            ; address of wave
  364.                     dc i2'0'            ; size of wave in pages..
  365. Rate                dc i2'$1AC'         ; sample rate 22Khz
  366.                     dc i2'$0100'        ; DOC starting address
  367.                     dc i2'$8000'        ; DOC buffer size
  368.                     dc i4'0'
  369. Vol1                dc i2'$00FF'        ; kinda medium..
  370.  
  371. ; Table of standard sampling rates 
  372. ;                        22khz,16khz,11khz, 8khz, filler
  373. RateTable           dc i2'$01ac,$0137,$00D6,$009C,$0000,$0000'
  374.  
  375.                     end
  376.  
  377.                     EJECT
  378. *******************************************************************************
  379. *
  380. EventLoop           start
  381. *
  382. * Description:      This is the main routine of the program. It creates a
  383. *                   Dialog box and handles all user selections that occur. When
  384. *                   the user selects quit, this routine exits and the program
  385. *                   will then end.
  386. *
  387. *
  388. * Inputs:           None
  389. *
  390. * Outputs:          None
  391. *
  392. * External Refs:
  393. *                   Import SFLoop
  394. *                   Import PlaySound
  395. *
  396. * Entry Points:     None
  397. *
  398. *******************************************************************************
  399.                     using Globals
  400.  
  401.                     PushLong #0         ; create the dialog this program
  402.                     PushLong #MyDialog  ; revolves around from a template
  403.                     _GetNewModalDialog
  404.                     PullLong theDialog  ; store its pointer into theDialog
  405.  
  406.                     lda #ItemRad22      ; reset radio buttons to the initial
  407.                     jsr RadHit          ; state of 22Khz default freq.
  408.  
  409.                     PushLong #NPNoFile  ; set the Paramtext ^0 item to
  410.                     PushLong #0         ; the initial file name of "no file"  
  411.                     PushLong #0
  412.                     PushLong #0
  413.                     _ParamText
  414.  
  415. EL0010              PushWord #0         ; now wait for a selection by the user
  416.                     PushLong #0
  417.                     _ModalDialog
  418.                     pla                 ; recover the item hit from the stack
  419.  
  420.                     cmp #ItemPlayB      ; is it the play button?
  421.                     bne EL0020          ; if not test next button
  422.                     jsr PlaySound       ; if it was the play button then play
  423.                     bra EL0010          ; the saved sound and get another hit
  424.  
  425. EL0020              ANOP
  426.                     cmp #ItemQuitB      ; is it the quit button?
  427.                     bne EL0030          ; if not test next button
  428.                     bra ELDone          ; if it was, end the program
  429.  
  430. EL0030              ANOP
  431.                     cmp #ItemLoadB      ; is it the load button?
  432.                     bne EL0040          ; if not test usr Rate item
  433.                     jsr SFLoop          ; if so, ask user for a new sound file
  434.                     bra EL0010          ; and get another hit
  435.  
  436. EL0040              ANOP
  437.                     cmp #ItemEditUsr    ; see if the user changed the usr rate
  438.                     bne EL0050          ; if not test radio buttons
  439.                     jsr SetUsr          ; if so, get the new value
  440.                     bra EL0010
  441. EL0050              ANOP
  442. ; If we get this far, the only thing we have left to test for is radio buttons
  443. ; and the radio buttons are items 4-8
  444.                     cmp #9              ; test to see if 3<ItemHit<9
  445.                     bge EL0060          ; if not then skip the next line
  446.                     jsr RadHit          ; if so then a radio button was hit
  447.                     bra EL0010          ; handle it and get another hit
  448.  
  449. EL0060              ANOP
  450.                     brl EL0010          ; this should not occur since no other
  451. ;                                         items are enabled
  452.  
  453. ; When the user selects quit the program branches here to close the dialog
  454. ; and go back and close down the program
  455. ELDone              ANOP
  456.                     PushLong theDialog  ; close the dialog and dispose of all
  457.                     _CloseDialog        ; memory used by it
  458.                     rts                 ; and return to the main loop
  459.  
  460. ; RadHit is called when the user selects any radio button. This routine
  461. ; turns off all radio buttons and turns on the one that the user hit.
  462. ; It then finds the correct value for the selected rate in RateTable
  463. ; and inserts  it into the waveform data.
  464. ; If the user selects the "User Supplied" sampling rate option, This
  465. ; routine will call SetUsr to obtain the users rate value.
  466. RadHit              ANOP
  467.                     sta Temp1           ; save the item hit number
  468.  
  469. ;                   PushWord #0         ; and turn off all radio buttons
  470. ;                   PushLong theDialog
  471. ;                   PushWord #ItemRad22
  472. ;                   _SetDItemValue;;
  473. ;
  474. ;                   PushWord #0
  475. ;                   PushLong theDialog
  476. ;                   PushWord #ItemRad16
  477. ;                   _SetDItemValue;
  478. ;
  479. ;                   PushWord #0
  480. ;                   PushLong theDialog
  481. ;                   PushWord #ItemRad11
  482. ;                   _SetDItemValue
  483. ;
  484. ;                   PushWord #0
  485. ;                   PushLong theDialog
  486. ;                   PushWord #ItemRad08
  487. ;                   _SetDItemValue
  488. ;
  489. ;                   PushWord #0
  490. ;                   PushLong theDialog
  491. ;                   PushWord #ItemRadUsr
  492. ;                   _SetDItemValue
  493.  
  494.                     PushWord #1         ; now turn on the radio button that 
  495.                     PushLong theDialog  ; was hit
  496.                     PushWord Temp1
  497.                     _SetDItemValue
  498.  
  499.                     lda Temp1           ; Check to see if the user button was hit
  500.                     cmp #ItemRadUsr
  501.                     beq SetUsr1         ; if so, get the user rate
  502.                     sec                 ; if not, get the new sampling rate
  503.                     sbc #4              ; subtract 4 from choice
  504.                     asl a               ; multiply it by 2
  505.                     tax                 ; use it as an index
  506.                     lda RateTable,x
  507.                     sta Rate
  508.                     rts
  509.  
  510. ; This routine gets the users input value from the "User Supplied" edit line item
  511. ; converts it to an integer and stores it as the current sampling rate
  512. SetUsr              ANOP
  513.                     PushWord #1
  514.                     PushLong theDialog
  515.                     PushWord #ItemRadUsr
  516.                     _SetDItemValue
  517. SetUsr1             ANOP
  518.                     PushLong theDialog  ; get the text from the user sampleing
  519.                     Pushword #ItemEditUsr ; rate item
  520.                     PushLong #tempAns
  521.                     _GetIText
  522.  
  523.                     PushWord #0         ; and convert it to an integer
  524.                     PushLong #tempAns+1 ; Skip the length byte
  525.                     lda tempAns         ; push the length byte seperately
  526.                     and #$00FF          ; after stripping off extra data
  527.                     pha
  528.                     _Hex2Int
  529.  
  530.                     pla                 ; store this number as the new rate
  531.                     sta Rate
  532.                     rts
  533. tempAns             ds 8
  534.  
  535.                     end
  536.  
  537.  
  538.                     EJECT
  539. *******************************************************************************
  540. *
  541. LoadSound           start
  542. *
  543. * Description:      Procedure that loads a selected file from disk and stores
  544. *                   it in RDDataBuf.
  545. *
  546. *
  547. * Inputs:           MyRFName should contain the full pathname of the file to load
  548. *
  549. * Outputs:          Data in the handle RDDataBuf
  550. *
  551. * External Refs:
  552. *                   Import PDosError
  553. *                   Import ToolError
  554. *
  555. * Entry Points:     None
  556. *
  557. *******************************************************************************
  558.                     using Globals
  559.  
  560.                     lda RDDataBuf       ; check handle to see if its already 
  561.                     ora RDDataBuf+2     ; allocated by seeing if its 0
  562.                     beq LS0010          ; if it is, skip next line
  563.  
  564.                     PushLong RDDataBuf  ; if non-zero then de-allocate
  565.                     _DisposeHandle      ; the memory
  566.  
  567. LS0010              ANOP
  568.                     _Open OPParms       ; open the file chosen by user
  569.                     bcc LS0015          ; no error, branch around next line
  570.                     jsr PDosError       ; got error, report to user
  571.                     brl LoadDone        ; and end this routine
  572.  
  573. LS0015              ANOP
  574.                     lda OPRefNum        ; save the file ref number into all
  575.                     sta RDRefNum        ; the other parm blocks 
  576.                     sta GERefNum
  577.                     sta CLRefNum
  578.  
  579. ; Now that the file is opened we ask ProDOS for the length of the file.
  580. ; Once recieved we create a handle to read the data into and update the FFRecord
  581. ; to reflect the size and location of the data.
  582.  
  583.                     _Get_EOF GEParms    ; Find out how big the file is
  584.                     bcc LS0020          ; so we can create the right sized buffer
  585.                     jsr PDosError       ; we got an error, so report it and...
  586.                     brl LoadCDone       ; file open was succesfull, so close it
  587. LS0020              ANOP
  588.                     lda GESize          ; first, update the read request count so
  589.                     sta RDReqCnt        ; read call knows how much to load
  590.                     lda GESize+2        ; Now get the high word of the file size
  591.                     sta RDReqCnt+2      ; and finish updating the read parms
  592.                     lda RDReqCnt+1      ; get the number of 256 byte pages
  593.                     sta MyFFRecord+4    ; and update the FFRecord
  594.  
  595.                     PushLong #0         ; reserve memory for the waveform
  596.                     PushLong GESize
  597.                     PushWord MyID
  598.                     PushWord #%1100000000001100
  599.                     PushLong #0
  600.                     _NewHandle
  601.                     bcc LS0025
  602.                     jsr ToolError
  603.                     brl LoadCDone
  604.  
  605. LS0025              ANOP
  606.                     pla                 ; dereference the handle to get the
  607.                     sta DeRef           ; pointer
  608.                     pla
  609.                     sta DeRef+2
  610.  
  611.                     lda [DeRef]
  612.                     sta RDDataBuf       ; store the pointer into the read parms 
  613.                     sta MyFFRecord      ; and the FFRecord
  614.  
  615.                     ldy #2
  616.                     lda [DeRef],y
  617.                     sta RDDataBuf+2
  618.                     sta MyFFRecord+2
  619.  
  620.                     _Read RDParms       ; Read the data from the file
  621.                     bcc LS0030
  622.                     jsr PDosError
  623.                     brl LoadCDone
  624. LS0030              ANOP
  625. LoadCDone           ANOP
  626.                     _Close CLParms      ; and finally close the file
  627.                     bcc LoadDone
  628.                     jsr PDosError
  629. LoadDone            ANOP
  630.                     rts                 ; and leave
  631.  
  632.                     end
  633.  
  634.                     EJECT
  635. *******************************************************************************
  636. *
  637. PlaySound           start
  638. *
  639. * Description:      Tell the sound managerto start the digitized sound
  640. *                   descripbed by myFFRecord
  641. *
  642. *
  643. * Inputs:           None
  644. *
  645. * Outputs:          None
  646. *
  647. * External Refs:    
  648. *                   Import ToolError
  649. *
  650. * Entry Points:     None
  651. *
  652. *******************************************************************************
  653.                     using Globals
  654.  
  655.                     PushLong theDialog  ; get the volume from the Dialog
  656.                     Pushword #ItemEditVol ; box. 
  657.                     PushLong #tempAns   ; 
  658.                     _GetIText
  659.  
  660.                     PushWord #0         ; convert the ASCII hexidecimal value to
  661.                     PushLong #tempAns+1 ; an integer.
  662.                     lda tempAns         ; load length of the string
  663.                     and #$00FF          ; strip off the high byte
  664.                     pha                 ; and push it onto the stack as out length
  665.                     _Hex2Int
  666.  
  667.                     pla
  668.                     sta Vol1            ; store this value into our volume
  669.  
  670.  
  671.                     PushWord #$0001     ; stop gen 0
  672.                     _FFStopSound
  673.  
  674.                     PushWord #$0001     ; and start the sound at gen 0
  675.                     PushLong #MyFFRecord
  676.                     _FFStartSound
  677.                     bcc PS0010          ; if no error then just end
  678.                     jsr ToolError       ; However, if an error occured report it
  679. PS0010              ANOP
  680.                     rts
  681.  
  682. tempAns             ds 8                ; temporary storage for the str convert
  683.  
  684.                     end
  685.  
  686. **********************************************************************************
  687. *
  688. *   SFLoop -    Throw up a sfGetFile dialog and let the user select file of
  689. *               their choice.
  690. *
  691.                     EJECT
  692. *******************************************************************************
  693. *
  694. SFLoop              start
  695. *
  696. * Description:      Call SFGetFile to obtain the users choice of sound file
  697. *                   to playback. If the user selects a valid file, load it and
  698. *                   play it. If the user selects cancel, do nothing.
  699. *
  700. *
  701. * Inputs:           None
  702. *
  703. * Outputs:          None
  704. *
  705. * External Refs:    
  706. *                   Import LoadSound
  707. *                   Import PlaySound
  708. *
  709. * Entry Points:
  710. *
  711. *******************************************************************************
  712.                     using Globals
  713.  
  714.                     PushWord #30        ; Location of dialog on screen
  715.                     PushWord #30
  716.  
  717.                     PushLong #PromptStr ; promtp for within the dialog
  718.                     PushLong #0         ; no filter proc
  719.                     PushLong #0         ; no type list
  720.                     PushLong #MyReply   ; record to put user selection
  721.                     _SFGetFile
  722.  
  723.                     lda MyRGood         ; test if cancel hit...
  724.                     sta QuitFlag        ; save it in quitflag
  725.                     beq SFQuit          ; and just quit
  726.  
  727.                     jsr LoadSound       ; Now load the file into the buffer
  728.                     jsr PlaySound       ; and play the loaded file
  729.  
  730.  
  731.                     PushLong #MyRName   ; set Param ^0 as the name of the
  732.                     PushLong #0         ; file for display in the didlog box
  733.                     PushLong #0
  734.                     PushLong #0
  735.                     _ParamText
  736.  
  737. SFQuit              rts
  738.                     end
  739.  
  740.                     EJECT
  741. *******************************************************************************
  742. *
  743. PDosError           start
  744. *
  745. * Description:      Reports an error to the user and calls it a ProDos error.
  746. *
  747. *
  748. * Inputs:           <A> - error code to report
  749. *
  750. * Outputs:          None
  751. *
  752. * External Refs:    None
  753. *
  754. * Entry Points:     None
  755. *
  756. *******************************************************************************
  757.                     using Globals
  758.  
  759.                     pha                 ; and convert the error to a string
  760.                     PushLong #ErrorNum
  761.                     PushWord #4
  762.                     _Int2Hex
  763.                     
  764. ; Use the window manager AlertWindow call to report the error message
  765.                     pha                 ; space for result
  766.                     PushWord #0         ; we are using P-Strings
  767.                     PushLong #SubStringA
  768.                     PushLong #AlertStr
  769.                     ldx #$590E          ; _AlertWindow
  770.                     jsl $E10000
  771.                     pla                 ; pull off button hit
  772.  
  773.  
  774.                     rts
  775. tempError           ds 2
  776. SubStringA          dc i4'ErrorNum'     ; substitution string array
  777. ErrorNum            dc c'xxxx',i1'0'
  778. AlertStr            dc c'24/ProDOS Error Loading File #*0/^#6'
  779.                     dc i1'0'
  780.  
  781.                     end
  782.  
  783.                     EJECT
  784. *******************************************************************************
  785. *
  786. ToolError           start
  787. *
  788. * Description:      Report an error to the user and say it was a tool error.
  789. *
  790. *
  791. * Inputs:           <A> error number to report
  792. *
  793. * Outputs:          None
  794. *
  795. * External Refs:    None
  796. *
  797. * Entry Points:     None
  798. *
  799. *******************************************************************************
  800.                     using Globals
  801.  
  802.                     pha
  803.                     PushLong #ErrorNum
  804.                     PushWord #4
  805.                     _Int2Hex
  806.  
  807.                     pha                 ; space for result
  808.                     PushWord #0         ; we are using P-Strings
  809.                     PushLong #SubStringA
  810.                     PushLong #AlertStr
  811.                     ldx #$590E          ; _AlertWindow
  812.                     jsl $E10000
  813.                     pla                 ; pull off button hit
  814.  
  815.  
  816.                     rts
  817. SubStringA          dc i4'ErrorNum'     ; substitution string array
  818. ErrorNum            dc c'xxxx',i1'0'
  819. AlertStr            dc c'24/Tool Error #*0/^#6'
  820.                     dc i1'0'
  821.  
  822.                     end
  823.  
  824.                     copy play.init.asm
  825.  
  826.                     END
  827.